<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function myAxious(options) {
            const {url, method = 'get', data} = options
            return new Promise((resolve, reject) => {
                const xhr = new XMLHttpRequest()
                xhr.open(method, url)
                xhr.setRequestHeader('content-type', 'application/json')
                xhr.addEventListener('load', function () {
                    resolve(JSON.parse(xhr.response))
                })
                xhr.send(JSON.stringify(data))
                
            })
        }
        myAxious({
            url : 'http://ajax-api.itheima.net/api/books' ,
            method : 'post',
            data : {
                bookname : '钢铁是怎么炼成的' ,
                author : '前苏联作家' ,
                publisher : '苏联共和国出版社'
            }
        }).then(res => {
            console.log(res)
        })
    </script>
</body>

</html>